//
//  AppDelegate.m
//  17作业
//
//  Created by dllo on 16/8/5.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "AppDelegate.h"
#import "ViewController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
//    实现文件、文件夹的基本操作(调研NSFileManager, 并实现以下功能)
//    创建文件、文件夹
//    删除文件、文件夹
//    文件 是否存在
//    移动文件
//    拷贝文件
//    使用tableView完成通讯录, 注意联系人使用类创建
//    添加联系人 联系人包含 头像 姓名 联系方式 家庭住址
//    联系人列表 (注意: 添加完联系人, 列表要刷新)
//    删除联系人
//    查看联系人详情
//    周报
//    博客
    
    _window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    _window.backgroundColor = [UIColor whiteColor];
    [_window makeKeyAndVisible];
    ViewController *vc = [[ViewController alloc] init];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
    [_window setRootViewController:nav];
    
    //    创建文件夹
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSString *docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] ;
    [fileManager changeCurrentDirectoryPath:docPath];
    
    if ([fileManager createDirectoryAtPath:@"我的文件夹" withIntermediateDirectories:YES attributes:nil error:nil]) {
        NSLog(@"不能创建文件夹");
    }
    if ([fileManager createDirectoryAtPath:@"他的文件夹" withIntermediateDirectories:YES attributes:nil error:nil]) {
        NSLog(@"不能创建文件夹");
    }
    //创建文件
    UIImage *image = [UIImage imageNamed:@"0"];
    NSData *imageData = UIImageJPEGRepresentation(image, 1);
    if ([fileManager createFileAtPath:@"图片" contents:imageData attributes:nil]) {
        NSLog(@"不能创建文件");
    }
    //    删除文件夹
    if ([fileManager removeItemAtPath:@"我的文件夹" error:nil] == NO) {
        NSLog(@"不能删除文件夹");
    }
    //    删除文件
    if ([fileManager removeItemAtPath:@"图片" error:nil]) {
        NSLog(@"不能删除文件");
    }
    //    文件是否存在
    if ([fileManager fileExistsAtPath:@"图片"]) {
        NSLog(@"文件存在");
    }
    //    移动文件
    if ([fileManager moveItemAtPath:@"图片" toPath:@"他的文件夹/tu" error:nil] == NO) {
        NSLog(@"不能移动文件夹");
        NSLog(@"%@",fileManager.currentDirectoryPath);
    }
    //    拷贝文件
    if ([fileManager copyItemAtPath:@"他的文件夹/tu" toPath:@"TuTu" error:nil]) {
        NSLog(@"不能拷贝文件");
    }

    
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
